<?php


defined('THINK_PATH') or exit();

class AdminCommAction extends CommAction
{
    protected function _initialize()
    {
        //后台自定义地址
        if (strpos(__SELF__, ADMINADSS) < 1) {
            $this->jumps(__ROOT__ . '/error.html');
        }
        import("ORG.Util.Auth");
        $auth = new \Think\Auth();
        $public_url = C("PUBLIC_URL");
        $rule_name = GROUP_NAME . '/' . MODULE_NAME . '/' . ACTION_NAME;
        $result = $auth->check($rule_name, $_SESSION['admin_uid']);
        if (!in_array($rule_name, $public_url)) {
            if (!($_SESSION['admin_uid']==1)) {
                if (!$result) {
                    $this->error('您没有权限访问');
                }
            }
        }
        header("Content-Type:text/html; charset=utf-8");
        $this->adminVerify();
    }

    /**
     * @后台验证
     */
    protected function adminVerify()
    {
        if ($this->_session('admin_uid')) {
            $users = M('admin')->field('username,password')->where(array('id' => $this->_session('admin_uid')))->find();
            if ($this->_session('admin_verify') !== MD5($users['username'] . DS_ENTERPRISE . $users['password'] . DS_EN_ENTERPRISE)) {
                session('admin_uid', null);
                session('admin_name', null);
                session('admin_verify', null);
                $this->error("请先重新登陆", '__APP__/ADMINADSS/Logo.html');
            }
        } else {
            $this->error("请先登陆", '__APP__/ADMINADSS/Logo.html');
        }
    }

    /**
     *
     * @后台添加
     */
    public function tfAdd()
    {
        $this->add();
    }

    /**
     *
     * @后台更新
     */
    public function tfUpda()
    {
        $this->upda();
    }

    /**
     *
     * @后台更新带验证码
     */
    public function tfUpdas()
    {
        if ($this->_session('verify') != md5($this->_post('proving'))) {
            $this->error('验证码错误！');
            exit;
        }
        $this->upda();
    }

    /**
     *
     * @后台删除
     */
    public function tfDel()
    {
        $this->del();
    }

    /**
     *
     * @带积分更新
     */
    public function iUpda()
    {
        $this->integral_upda();
    }

    /**
     *
     * @后台更新带验证码
     */
    public function iUpdas()
    {
        if ($this->_session('verify') != md5($this->_post('proving'))) {
            $this->error('验证码错误！');
            exit;
        }
        $this->integral_upda();
    }
}

?>